package com.example.vote.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class RedirectController {

    @Value("${qr_path}")
    String qrPath;

    @RequestMapping("/redirect")
    public String index(String item) {
        return "redirect:" + qrPath + "?item=" + item;
    }

    @GetMapping("/vote")
    public void vote(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/vote/index.html").forward(request, response);
    }

}
